import {Actor, Action} from 'iflux2';
import {fromJS} from 'immutable';

import {defaultParam} from 'actor/pagination';
import {SearchActionType} from '../constant/action-type';
import { PaginationType } from 'actor/pagination/type';

export default class SearchActor extends  Actor {

    defaultState() {
        return {
            filterKey: '',//当前选中的过滤菜单选项
            filters:[],//当前过滤菜单列表
           // pagination: defaultParam,
            search:{
                //itemName:'',//商品名称
                //startTime:'',
                //endTime:"",
                //buyerUserName:'',//会员名称
               // isNeedReturn:'',
            }
        }
    }

    @Action(SearchActionType.SET_SEARCH_PARAM)
    setSearchParam(state,param){
        return state.set('search',param);
    }
    /**
     * 设置订单状态
     * @param state
     * @param filterKey
     */
    @Action(SearchActionType.SET_SEARCH_FILTER)
    setFilter(state, filterKey) {
        return state.set('filterKey', filterKey);
    }

    @Action(SearchActionType.SET_FILTERS)
    setFilters(state, newfilters) {
        return state.set('filters', newfilters);
    }

    /**
     * 修改分页信息
     * @param state
     * @param pagination
     */
    // @Action(SearchActionType.CHANGE_SEARCH_PAGINATION)
    // changePagination(state, pagination) {
    //     return state.update('pagination', (page)=>page.merge(pagination));
    // }


    /**
     * 重置分页信息
     * @param state
     */
    @Action(PaginationType.RESET_PAGINATION_PARAM)
    resetPagination(state) {
        return state.set('pagination', fromJS(defaultParam));
    }
}